﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jumpton.Persistent;
using Jumpton.SFA.Server.Entity;
using System.Data;

namespace Jumpton.SFA.Server.BusinessRule.MasterData
{
    public class TaxesManager:BusinessLogic
    {
        public TAXES Load(int ID)
        {
            return (TAXES)ObjectRow.Load(typeof(TAXES), string.Format("this.ID={0}", ID));
        }

        public TAXES LoadName(string DESCRIPTION, decimal DomainID,decimal ID)
        {
            return (TAXES)ObjectRow.Load(typeof(TAXES), string.Format("this.DESCRIPTION='{0}' AND this.DOMAINID='{1}' AND this.ID<>'{2}'", DESCRIPTION, DomainID, ID));
        }

        public static ObjectTable GetTaxesTable(decimal domainid)
        {
            return new ObjectTable(typeof(TAXES), "this.DOMAINID='" + domainid + "'");
        }

        //public static ObjectTable GetCountryType()
        //{
        //    return new ObjectTable(typeof(COUNTRIES));
        //}

        /// <summary>
        /// 保存税率信息
        /// </summary>
        /// <param name="taxes"></param>
        /// <returns></returns>
        public bool Save(TAXES taxes)
        {
            try
            {
                if (LoadName(taxes.DESCRIPTION, taxes.DOMAINID,taxes.ID) != null)
                {
                    throw new Exception("名称已存在");
                }
               
                
                taxes.Save();
                
                return true;
            }
            catch (Exception ex)
            {
                this.message = ex.Message;
                throw ex;
            }
        }

    }
}
